import java.util.Scanner;

public class demo04 {
//    洁净数
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int count=0;
        for(int i=0;i<n;i++){
            int tmp=i;
            int flag=1;
            while(tmp!=0){
                if(tmp%10==2){
                    flag=0;
                    break;
                }
                tmp/=10;
            }
            if(flag==1){
                count++;
            }
        }
        System.out.println(count);
        sc.close();
    }
}
